int debounce(int pin, int x)
{
    static int status = 0;

    if (status < 2 && !input(pin))
        status++;
    if (status == 2 && !input(pin))
    {
        x++;
        status = 5;
    } else if (input(pin))
    {
        status = 0;
    }
    return x;
}